package com.example.demo.Mapper;

import com.example.demo.Entity.Medicalrecords;
import com.example.demo.Entity.transfer.MedicalrecordsDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MedicalrecordsMapper {

    //根据手机号查病例
    @Select("select * from medicalrecords where phone=#{phone}")
    List<Medicalrecords> getMedicalrecordsByPhone(@Param("phone") String phone);


    //查病例
    @Select("select * from medicalrecords ")
    List<Medicalrecords> getMedicalrecords();


    //根据userid号查病例
    @Select("select * from medicalrecords where user_id=#{user_id}")
    List<Medicalrecords> getMedicalrecordsByUserId(@Param("user_id") int user_id);

    //根据id号查病例
    @Select("select * from medicalrecords where id=#{id}")
    Medicalrecords getMedicalrecordsById(@Param("id") int id);


    //根据id号查病例
    @Select("select * from medicalrecords where id=#{id}")
    List<Medicalrecords> getMedicalrecordListById(@Param("id") int id);

    //根据id号删病例
    @Delete("delete from medicalrecords where id=#{id}")
    int deleteMedicalrecordsById(@Param("id") int id);


    @Insert("INSERT INTO medicalrecords (user_id,otpatientservice,idcard,hospital,phone,name,age,sex,address,diagnosis,pathologicaltype,conclusion,reportingunit,reportthephysician,cordbase64,create_time) " +
            "VALUES(#{user_id},#{otpatientservice},#{idcard},#{hospital},#{phone},#{name},#{age},#{sex}," +
            "#{address}," +
            "#{diagnosis},#{pathologicaltype},#{conclusion},#{reportingunit},#{reportthephysician},#{cordbase64},NOW());")
    int addMedicalrecords(MedicalrecordsDTO medicalrecordsDTO);

    /**
     * 根据id修改病例
     * @param medicalrecordsDTO
     * @return int
     * */
    @Update("<script> \n"+
            "update medicalrecords  <set><if test=' otpatientservice != null '> otpatientservice = " +
            "#{otpatientservice}, </if>" +
            "<if test=' idcard != null '> idcard=#{idcard} , </if> "+
            "<if test=' hospital != null '> hospital=#{hospital} , </if> "+
            "<if test=' phone != null '> phone=#{phone}  ,</if> "+
            "<if test=' name != null '> name=#{name}  ,</if> "+
            "<if test=' age != null '> age=#{age}  ,</if> "+
            "<if test=' sex != null '> sex=#{sex} , </if> "+
            "<if test=' address != null '> address=#{address},  </if> "+
            "<if test=' diagnosis != null '> diagnosis=#{diagnosis} , </if> "+
            "<if test=' pathologicaltype != null '> pathologicaltype=#{pathologicaltype} , </if> "+
            "<if test=' conclusion != null '> conclusion=#{conclusion}  ,</if> "+
            "<if test=' reportingunit != null '> reportingunit=#{reportingunit} , </if> "+
            "<if test=' reportthephysician != null '> reportthephysician=#{reportthephysician},  </if> "+
            "<if test=' cordbase64 != null '> cordbase64=#{cordbase64},  </if> "+
            "</set> where id = #{id}</script> ")
    int update(MedicalrecordsDTO medicalrecordsDTO);

}
